package com.zhuss.core.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.core.part.CreatePartBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.core.db.dao.ext.PartDao;
import com.zhuss.core.db.entity.Part;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.util.JsonUtil;

/**
 * 创建区域 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("partCreate")
public class PartCreate extends AbstractProcessor<Object, CreatePartBo> implements Processor<Object, CreatePartBo> {

    @Autowired
    private PartDao partDao;
    
    @Autowired
	@Qualifier("partRead")
	private PartRead partRead;
    
    
    /**
     * 校验
     */
    @Override
    public void check(CreatePartBo bo) throws WpsException {
    	
    	// bo.setArea(partRead.findMaxAreaIncr());
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(CreatePartBo param) {
    	Part record = new Part();
    	record.setArea(param.getArea());
    	record.setSort(param.getSort());
    	record.setPic(param.getPic());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	partDao.create(record);
    	param.setTargetId(record.getPartId());
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(CreatePartBo param) throws WpsException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.基础模块.key());
    	record.setAction(LogActionEnum.区域创建.key());
    	record.setTargetId(param.getTargetId());
    	record.setTargetName(param.getArea() + "");
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
